const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');

module.exports = {
  mode: "none",
  entry: path.join(__dirname, './src/main.js'),// 入口文件
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, './dist'),
  },
  plugins: [
    new CleanWebpackPlugin(),// 清楚dist文件
    new HtmlWebpackPlugin({
      title: 'this is demo',
      template: path.join(__dirname, './public/index.html'),
    }),// 生成html文件
    new webpack.DefinePlugin({
      BASE_URL: '"./"',
    }),// 设置全局参数
    new StyleLintPlugin({
      files: ['**/*.{css,sss,less,scss,sass}'],
    }),
    new VueLoaderPlugin(),// 把其他功能插件应用在vue文件
  ],
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: file => (
          /node_modules/.test(file) && !/\.vue\.js/.test(file)
        )
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
      },
      {
        test: /\.css$/,
        use: [
          'vue-style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.less$/,
        use: [
          'vue-style-loader',
          'css-loader',
          'less-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif)$/,
        use: {
          loader: 'url-loader',
          options: {
            esModule: false,
            limit: 10240,
          }
        }
      }
    ]
  }
}